﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PRJ_LDW_Eutoliso.AccountAdmin.Veiculo.Tipo
{
    public partial class Edit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                try
                {

                    string idVeiculoTipo = Request.QueryString["Id"].Trim();

                    eutolisodbEntities1 context = new eutolisodbEntities1();

                    int id_VeiculoTipo = Convert.ToInt32(idVeiculoTipo);

                    var _query = (from vet in context.veiculotipo
                                  where vet.Id == id_VeiculoTipo
                                  select new
                                  {
                                      vet.Id,
                                      vet.Nome

                                  });


                    foreach (var Result in _query)
                    {
                        txtNome.Text = Result.Nome;

                    }


                }
                catch (Exception)
                {


                }

            }

        }

        protected void btnEdit_Click(object sender, EventArgs e)
        {
            try
            {

                string idVeiculoTipo = Request.QueryString["Id"].Trim();
                eutolisodbEntities1 context = new eutolisodbEntities1();

                int id_VeiculoTipo = Convert.ToInt32(idVeiculoTipo);

                var _query = (from vet in context.veiculotipo
                              where vet.Id == id_VeiculoTipo
                              select vet).First();



                _query.Nome = txtNome.Text;


                context.SaveChanges();

                lblMsg.Visible = true;

            }


            catch (Exception)
            {
                lblMsg.Visible = true;
                lblMsg.Text = "Ocorreu um problema ao editar o item.";
            }

            Response.Redirect("Home.aspx");
        }

        protected void btnCancelar_Click(object sender, EventArgs e)
        {
            Response.Redirect("Home.aspx");
        }
    }
}